#ifndef STRATEGY_USER_4_H_
#define STRATEGY_USER_4_H_
#pragma once
#include "strategy_sys.h"


typedef struct userdata_stra4
{
	userdata_stra4()//:ASK1PRICE("AskPrice1"), BID1PRICE("BidPrice1")
	{
		reqvol = 0;
		tradeprice = 0;

		direct = 0; //THOST_FTDC_D_Buy for up  THOST_FTDC_D_Sell for down 
		offset = 0;
		memset(inst, 0, sizeof(inst));
		memset(str_tradeprice, 0, sizeof(str_tradeprice));

	}

	
	
	char offset; //#define THOST_FTDC_OF_Open '0' // #define THOST_FTDC_OF_CloseToday '3'

	char direct;//THOST_FTDC_D_Buy  '0'  //THOST_FTDC_D_Sell '1'

	int reqvol; 

	double tradeprice;



	
	//used to compare with inst_map first key
	char inst[8];

	char str_tradeprice[10];

}userdata_stra4;



namespace StrategyUser4_CInstMap_NameSpace
{
	class CInstMap
	{
	public:

		//CInstMap(const char* pinst, int vol, double _pricetick, unsigned int _stopcnt_cl, BarSeries* _pbarser);

		CInstMap(userdata_stra4* puserdata, double _pricetick);

		~CInstMap();


	public:

		int state;

		userdata_stra4 userdata; 

		double askprice1;

		double bidprice1;

		double pricetick;

		TThostFtdcOrderRefType orderref;






		static const string ASKPRICE1;

		static const string BIDPRICE1;

		static const string OPEN;

		static const string CLOSE;

		static const string BUY;

		static const string SELL;

	};
}



class CStrategyUser4: public CStrategySys
{
	

public:

	CStrategyUser4(string threadid);


	virtual ~CStrategyUser4(){};

private:

	virtual bool Init(BarInfo* pbar, map<string, vector<BarSeries*>>& mapuserbar, char* puserdata = NULL);

	virtual bool Destroy(BarInfo* pbar, map<string, vector<BarSeries*>>& mapuserbar);

	virtual bool Edit(BarInfo* pbar, char* puserdata);

	virtual void Run(BarData* ptickdata, char* inst);

	virtual void OnOrder(CThostFtdcOrderField *pOrder);

	virtual void OnTrade(CThostFtdcTradeField *pTrade);

	virtual void OnCancelOrder(CThostFtdcOrderField *pOrder);

	virtual void OnCancelOrderFailed(CThostFtdcInputOrderActionField *pCancelOrderFailed);

	virtual void OnStrategyCom(unsigned int size, char* pdata);

private:

	//bool Open(BarData* ptickdata, StrategyUser4_CInstMap_NameSpace::CInstMap* pinstmap);

	bool FindInstMap(userdata_stra4* pdata, StrategyUser4_CInstMap_NameSpace::CInstMap* &pinstmap/*out*/);

	bool FindInstMap(char* inst, StrategyUser4_CInstMap_NameSpace::CInstMap* &pinstmap/*out*/);

	bool Open(StrategyUser4_CInstMap_NameSpace::CInstMap* pinstmap);

	void Print_SyncOrder(CThostFtdcOrderField *order);


	/*void InitTradetime();

	bool InTradeTime(SYSTEMTIME& curtime);*/

private:

	map<string , StrategyUser4_CInstMap_NameSpace::CInstMap* > inst_map;

	//SYSTEMTIME tradetime[0];

};





#endif